﻿using System.Windows;
using System.Diagnostics;
using MediaAssistant.DAL.Helper;

namespace MediaAssistant.Controls.SplashScreen
{
    public class MessageListener : DependencyObject
    {
        private static MessageListener mInstance;

        private MessageListener ( )
        {

        }

        public static MessageListener Instance
        {
            get { return mInstance ?? (mInstance = new MessageListener()); }
        }

        public void ReceiveMessage ( string message )
        {
            Message = message;
            Debug.WriteLine ( Message );
            Logger.Instance.Write(message);
            DispatcherHelper.DoEvents();
        }
       
        public string Message
        {
            get
            {
                return ( string ) GetValue ( MessageProperty );
            }
            set
            {
                SetValue ( MessageProperty, value );
            }
        }
        
        public Visibility BusyIconVisibility
        {
            get
            {
                return (Visibility)GetValue(BusyIconVisibilityProperty);
            }
            set
            {
                SetValue(BusyIconVisibilityProperty, value);
                DispatcherHelper.DoEvents();
            }
        }

        public static readonly DependencyProperty BusyIconVisibilityProperty =
            DependencyProperty.Register("BusyIconVisibility", typeof(Visibility), typeof(MessageListener), new UIPropertyMetadata(Visibility.Hidden));


        public static readonly DependencyProperty MessageProperty =
            DependencyProperty.Register ( "Message", typeof ( string ), typeof ( MessageListener ), new UIPropertyMetadata ( null ) );

    }
}